Don't be discouraged. Usually things work as you expect. If you can do math with an electronic calculator then you can do it with Java. Occasionally there are annoying details, but that is true of calculators, also.
Here is another excerpt from the Java documentation:
PI public static final double PI The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.
The reserved word final in this means that the value PI
will not change.
Often you need the value π in a program. The way to
get it is to say Math.PI
(the PI must be upper case).
Here is an example:
double x = Math.PI;
Java has trigonometic functions, just like a calculator.
For example it has the function Math.cos()
.
Do you expect that the argument to Math.cos()
to be in radians or in degrees?